<template>
  <div>
    <form @submit.prevent="onSubmit">
      <!-- account -->
      <div>
        <label for="account">账号</label>
        <input type="text" v-model="account" />
      </div>
      <!-- password-->
      <div>
        <label for="password">密码</label>
        <input type="password" v-model="password" />
      </div>
      <!-- confimPassword -->
      <div>
        <label for="comfirmPassword">确认密码</label>
        <input type="password" v-model="comfirmPassword" />
      </div>
      <button type="submit">注册</button>
      <!-- <a href="#">已有账号，登录</a> -->
      <router-link :to="{name:'loginLink'}">已有账号，登录</router-link>
    </form>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      account: "",
      password: "",
      comfirmPassword: ""
    };
  },
  methods: {
    onSubmit() {
      //   console.log(12321);
      if (this.password === this.comfirmPassword) {
        // console.log(11);
        const formData = {
          account: this.account,
          password: this.password,
          comfirmPassword: this.comfirmPassword
        };
        axios.post("/user.json", formData).then(res => {
          //   console.log(res);
          this.$router.push({ name: "loginLink" });
          //   this.$router.push("/login");
        });
      } else {
        alert("两次密码不一致!");
      }
    }
  }
};
</script>